'use strict';

const md5 = require('md5');

module.exports = app => {

  // const store = {};
  // app.sessionStore = {
  //   async get(key) {
  //     return store[key];
  //   },
  //   async set(key, value, maxAge) {
  //     store[key] = value;
  //   },
  //   async destroy(key) {
  //     store[key] = null;
  //   },
  // };
  //
  app.beforeStart(async () => {
    // await app.model.sync({ force: true, alter: true });
    // await app.model.User.bulkCreate([
    //   { userName: 'admin', password: md5('123456' + app.config.salt), nickName: '管理员' },
    // ]);
    // await app.model.Role.bulkCreate([
    //   { name: '普通用户', auth: '1', description: '这是普通用户' },
    //   { name: '管理员', auth: 'all', description: '这是管理员' },
    // ]);
    // await app.model.UserInfo.bulkCreate([
    //   { uid: 1 },
    // ]);
    // await app.model.UserAndRole.bulkCreate([
    //   { uid: 1, rid: 2 },
    // ]);
    // await app.model.UserRelation.bulkCreate([
    //   { uid: 1, followId: 1 },
    // ]);
    // await app.model.Menu.destroy({
    //   truncate: true,
    // });
    // await app.model.Menu.bulkCreate([
    //   { name: '用户', href: '/user', type: 'PC' },
    //   { name: '民宿', href: '/house', type: 'PC' },
    //   { name: '论坛', href: '/comment', type: 'PC' },
    //   { name: '订单', href: '/order', type: 'PC' },
    //   { name: '系统', href: '/sys', type: 'PC' },
    //   { name: '民宿', href: '/house', type: 'mobile' },
    //   { name: '论坛', href: '/comment', type: 'mobile' },
    //   { name: '预约', href: '/appointment', type: 'mobile' },
    //   { name: '收藏', href: '/collection', type: 'mobile' },
    //   { name: '订单', href: '/order', type: 'mobile' },
    //   { name: '我的', href: '/user', type: 'mobile' },
    //   { name: '统计模块', href: '/statistics', type: 'PC' },
    //   { name: '用户查看', href: '/userManage', parentId: 1, type: 'PC' },
    //   { name: '信息查看', href: '/userInfoManage', parentId: 1, type: 'PC' },
    //   { name: '信息设置', href: '/userInfoSetting', parentId: 1, type: 'PC' },
    //   { name: '民宿查看', href: '/houseManage', parentId: 2, type: 'PC' },
    //   { name: '信息查看', href: '/houseInfoManage', parentId: 2, type: 'PC' },
    //   { name: '特点管理', href: '/advantageManage', parentId: 2, type: 'PC' },
    //   { name: '设备管理', href: '/deviceManage', parentId: 2, type: 'PC' },
    //   { name: '民宿审核', href: '/houseExamine', parentId: 2, type: 'PC' },
    //   { name: '信息审核', href: '/houseInfoExamine', parentId: 2, type: 'PC' },
    //   { name: '我的民宿', href: '/houseSetting', parentId: 2, type: 'PC' },
    //   { name: '信息设置', href: '/houseInfoSetting', parentId: 2, type: 'PC' },
    //   { name: '特点设置', href: '/advantageSetting', parentId: 2, type: 'PC' },
    //   { name: '设备设置', href: '/deviceSetting', parentId: 2, type: 'PC' },
    //   { name: '论坛查看', href: '/commentManage', parentId: 3, type: 'PC' },
    //   { name: '论坛审核', href: '/commentExamine', parentId: 3, type: 'PC' },
    //   { name: '回复查看', href: '/replyManage', parentId: 3, type: 'PC' },
    //   { name: '回复审核', href: '/replyExamine', parentId: 3, type: 'PC' },
    //   { name: '预约查看', href: '/appointmentManage', parentId: 4, type: 'PC' },
    //   { name: '订单查看', href: '/orderManage', parentId: 4, type: 'PC' },
    //   { name: '租约查看', href: '/leaseManage', parentId: 4, type: 'PC' },
    //   { name: '预约管理', href: '/appointmentSetting', parentId: 4, type: 'PC' },
    //   { name: '订单管理', href: '/orderSetting', parentId: 4, type: 'PC' },
    //   { name: '租约管理', href: '/leaseSetting', parentId: 4, type: 'PC' },
    //   { name: '地区管理', href: '/areaManage', parentId: 5, type: 'PC' },
    //   { name: '角色管理', href: '/roleManage', parentId: 5, type: 'PC' },
    //   { name: '授权管理', href: '/authManage', parentId: 5, type: 'PC' },
    //   { name: '统计收入', href: '/statisticalIncome', parentId: 12, type: 'PC' },
    //   { name: '房屋收入', href: '/statisticalHouse', parentId: 12, type: 'PC' },
    //   { name: '热度统计', href: '/statisticalOther', parentId: 12, type: 'PC' },
    //   { name: '统计收入(全部)', href: '/statisticalSys', parentId: 12, type: 'PC' },
    //   { name: '房屋收入(全部）', href: '/statisticalHouseAll', parentId: 12, type: 'PC' },
    //   { name: '热度统计（全部）', href: '/statisticalOtherAll', parentId: 12, type: 'PC' },
    //   { name: '系统统计', href: '/statisticalSys', parentId: 12, type: 'PC' },
    //   { name: '地图选房', href: '/houseMap', parentId: 6, type: 'mobile' },
    //   { name: '民宿详情', href: '/house', parentId: 6, type: 'mobile' },
    //   { name: '猜你喜欢', href: '/like', parentId: 6, type: 'mobile' },
    //   { name: '排行榜', href: '/houseRankList', parentId: 6, type: 'mobile' },
    //   { name: '发布论坛', href: '/commentAdd', parentId: 7, type: 'mobile' },
    //   { name: '论坛详情', href: '/comment', parentId: 7, type: 'mobile' },
    //   { name: '预约申请', href: '/appointmentAdd', parentId: 8, type: 'mobile' },
    //   { name: '预约详情', href: '/appointment', parentId: 8, type: 'mobile' },
    //   { name: '订单详情', href: '/order', parentId: 10, type: 'mobile' },
    //   { name: '设置', href: '/edit', parentId: 11, type: 'mobile' },
    //   { name: '联系人设置', href: '/personManage', parentId: 11, type: 'mobile' },
    //   { name: '个人主页', href: '/userDetail', parentId: 11, type: 'mobile' },
    //   { name: '联系人修改', href: '/personEdit', parentId: 11, type: 'mobile' },
    //   { name: '我的关注', href: '/follow', parentId: 11, type: 'mobile' },
    //   { name: '我的粉丝', href: '/beFollow', parentId: 11, type: 'mobile' },
    //   { name: '我的租约', href: '/lease', parentId: 11, type: 'mobile' },
    //   { name: '我的回复', href: '/myReply', parentId: 11, type: 'mobile' },
    //   { name: '租约详情', href: '/leaseDetail', parentId: 11, type: 'mobile' },
    // ]);

    // await app.model.Menu.bulkCreate([
    //   { name: '猜你喜欢', href: '/like', parentId: 6, type: 'mobile' },
    // ]);
  });


  app.config.coreMiddleware.unshift('auth');
  app.config.coreMiddleware.unshift('getDeviceType');
  app.config.coreMiddleware.unshift('notFound');
  app.config.coreMiddleware.unshift('allowHosts');
  app.config.coreMiddleware.unshift('interfaceLimit');
};
